package com.soecode.lyf.dto;

import java.util.List;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;

import net.sf.json.JSONArray;

/**
 * 封装json对象，所有返回结果都使用它
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private T data;// 成功时返回的数据
	
	private int code; // 0=代表数据请求成功  1=代表请求失败  5=登录失效
	
	private String desc;
	public Result() {
		
	}

	// 成功时的构造器
	public Result(int code , T data, String str) {
		if(code==0) {
		this.code = 0;
		this.data = data;
		this.desc = str;
		}else if (code == 1){
		this.code = 1;
		this.data = null;
		this.desc = str;
		}
	}

	public Result(int code , String str) {
		this.code = code;
		this.desc = str;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
    
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}
	
	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	@Override
	public String toString() {
		return "JsonResult [data=" + data +"]";
	}

}
